<?php
namespace Controller\Wcc;

use Controller\BaseController;
use Hoa\Registry\Registry;
use Library\Input;
use Library\Log;
use Library\View;
use Requests;


/**
 * ReorderController
 * @author los_gsy
 */
class ReorderController extends BaseController {
	/**
	 * 构造函数
	 */
	public function __construct() {
		parent::__construct();
	}


	/**
	 * test
	 */
	public function test() {
		echo __METHOD__, '<br />';
	}


	/**
	 * 下单
	 */
	public function placeReorder() {
		//定义变量
		$conf = Registry::get('conf');
		$wcc_fw_reorder = $conf['wcc']['fw_reorder'];
		$now = time();

		//http接口参数
		$url = $wcc_fw_reorder['url']['place_reorder'];
		$header = ['Accept' => 'application/json'];
		$option = [];

		$data = [];
		$data['uid'] = mt_rand(10000, 20000);
		$data['order_id'] = mt_rand(10000, 20000);
		$data['type'] = mt_rand(1, 3);
		$data['issue'] = 'issue' . $data['uid'];
		$data['has_invoice'] = mt_rand(0, 1);
		$data['name'] = 'name' . $data['uid'];
		$data['mobile'] = mt_rand(0, 9);
		$data['tel'] = mt_rand(0, 9);
		$data['email'] = $data['name'] . '@wcc.cn';
		$data['remark'] = 'remark' . $data['uid'];

		$prod = [];
		$prod['id'] = mt_rand(10000, 20000);
		$prod['type'] = mt_rand(1, 3);
		$prod['name'] = 'name'. $prod['id'];
		$prod['attr'] = 'name' . $prod['id'];
		$prod['preferential_prod_amt'] = floatval(mt_rand(100, 1000)) / 100;
		$data['prod'] = $prod;

		//执行远程调用
		$resp = Requests::post($url, $header, $data, $option);
		$result = json_decode($resp->body, true);
		var_export($result);
		echo '<br />';
		print_r($resp);
	}


	/**
	 * 取消订单
	 */
	public function cancelReorder() {
		//获取参数
		$id = Input::get('id', 0);

		//定义变量
		$conf = Registry::get('conf');
		$wcc_fw_reorder = $conf['wcc']['fw_reorder'];

		//http接口参数
		$url = $wcc_fw_reorder['url']['cancel_reorder'];
		$header = ['Accept' => 'application/json'];
		$option = [];

		$data = [];
		$data['id'] = $id;

		//执行远程调用
		$resp = Requests::post($url, $header, $data, $option);
		$result = json_decode($resp->body, true);
		var_export($result);
		echo '<br />';
		var_export($resp);
	}


	/**
	 * 查询订单
	 */
	public function getReorder() {
		//获取参数
		$id = Input::get('id', 0);

		//定义变量
		$conf = Registry::get('conf');
		$wcc_fw_reorder = $conf['wcc']['fw_reorder'];

		//http接口参数
		$url = $wcc_fw_reorder['url']['get_reorder'];
		$header = ['Accept' => 'application/json'];
		$option = [];

		$data = [];
		$data['id'] = $id;
		$url .= '?' . http_build_query($data);

		//执行远程调用
		$resp = Requests::get($url, $header, $option);
		$result = json_decode($resp->body, true);
		var_export($result);
// 		echo '<br />';
// 		var_export($resp);
	}








}